﻿using Share;
using Microsoft.SemanticKernel;
using PluginDemo;
using Microsoft.SemanticKernel.ChatCompletion;
using Microsoft.SemanticKernel.Connectors.OpenAI;

var kernel = Kernel.CreateBuilder()
     .AddOpenAIChatCompletion(
    modelId: "gpt-3.5-turbo",
    apiKey: "sk-9gH1lRVZemdh4eStDMJllCSLLt9VTq4ls18orr",
    httpClient: new HttpClient(new OpenAIHttpClientHandler("https://api.token-ai.cn/")))
    .Build();

// 加载时间插件
kernel.Plugins.AddFromType<TimeInformationPlugin>();
// 加载天气插件
//kernel.Plugins.AddFromType<WeatherInformationPlugin>();

// 获取聊天完成服务
var chatCompletionService = kernel.GetRequiredService<IChatCompletionService>();

// 启用自动函数调用
OpenAIPromptExecutionSettings openAIPromptExecutionSettings = new()
{
    ToolCallBehavior = ToolCallBehavior.AutoInvokeKernelFunctions
};

ChatHistory history = [];

string? input = null;

history.AddUserMessage("现在几点了");
var chatResult = await chatCompletionService.GetChatMessageContentsAsync(history, openAIPromptExecutionSettings, kernel);

Console.Write($"\nAssistant > {chatResult[0]}\n");


history.AddUserMessage("中山属于哪个省");

chatResult = await chatCompletionService.GetChatMessageContentsAsync(history, openAIPromptExecutionSettings, kernel);
Console.Write($"\nAssistant > {chatResult[0]}\n");
